﻿using Hidistro.Core;
using Hidistro.Core.Enums;
using Hidistro.Entities.Commodities;
using Hidistro.Membership.Context;
using Hidistro.SaleSystem.Catalog;
using Hidistro.UI.Common.Controls;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI.WebControls;
using System.Xml;
using wnxd_feature;

namespace Hidistro.UI.SaleSystem.Tags
{
    public class wnxd_SortList : AscxTemplatedWebControl
    {
        private Repeater PList;
        private XmlDocument xml;
        protected override void AttachChildControls()
        {
            this.PList = (Repeater)this.FindControl("PList");
            this.PList.ItemDataBound += PList_ItemDataBound;
            xml = new XmlDocument();
            xml.Load(HttpContext.Current.Request.MapPath(HiContext.Current.GetSkinPath() + "/config/wnxd_subpage.xml"));
        }

        private void PList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                CategoryInfo ci = (CategoryInfo)e.Item.DataItem;
                Repeater GList = (Repeater)e.Item.FindControl("GList");
                GList.DataSource = new Juse.Interface.ProductBrowser().GetOrderByProductByTowCategoryId(ci.CategoryId, "ShowSaleCounts desc", 6);
                GList.DataBind();
            }
        }
        protected override void OnInit(EventArgs e)
        {
            if (this.SkinName == null)
            {
                this.SkinName = "/ascx/tags/Common_GoodsList/wnxd_SortList.ascx";
            }
            base.OnInit(e);
        }
        public object DataSource
        {
            get
            {
                return this.PList.DataSource;
            }
            set
            {
                this.EnsureChildControls();
                this.PList.DataSource = value;
            }
        }
        public override void DataBind()
        {
            this.EnsureChildControls();
            if (this.PList.DataSource != null) this.PList.DataBind();
        }
        public string GetSortImg(string categoryid, int index)
        {
            XmlNode node = xml.SelectSingleNode(string.Format("//url[@cid='{0}' and @i='{1}']", categoryid, index));
            string url = node == null ? "" : node.InnerText, href = node == null ? "" : node.Attributes["href"].Value;
            return string.Format("<a class=\"{0}\" target=\"_blank\" href=\"{1}\"><img src=\"http://image.juseshop.com{2}\"></a>", index == 0 ? "h415" : "h232", href, url);
        }
        public string GetSortbitImg(string categoryid, int index)
        {
            XmlNode node = xml.SelectSingleNode(string.Format("//url[@cid='{0}' and @i='{1}']", categoryid, index));
            string url = "http://image.juseshop.com/shopsanqi/cp2.jpg";
            string href = "/it_nvxing/product_detail-1129.html";
            string pic = "222";
            string tab = string.Empty;
            string name = "默认产品";
            string Fname ="用了都说好。叼叼叼";
            if (node != null &&node.Attributes["pic"]!=null)
            {
                url = "http://image.juseshop.com"+node.InnerText;
                href = node.Attributes["href"].Value;
                pic = "¥"+node.Attributes["pic"].Value;
                name = node.Attributes["name"].Value;
                Fname = node.Attributes["Fname"].Value;
                tab = node.Attributes["tab"].Value;

            }

            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("<li><a target=\"_blank\" href=\"{0}\">", href);
            sb.AppendFormat("<img src=\"{0}\"></a>", url);
            sb.AppendFormat("   <p class=\"ewrger\"><a href=\"{0}\">{1}</a></p><p><i>{2}</i></p>", href, name,Fname);
            sb.AppendFormat("<span class=\"yanse\"><b>{0}</b></span>", pic);
            //sb.AppendFormat("<div class=\"cu\"><img src=\"http://image.juseshop.com/shopsanqi/cu.png\"></div><div class=\"baoyou\">包邮</div>");
            sb.AppendFormat("<a  target=\"_blank\" class=\"chakanxianqing\" href=\"{0}\">查看详情</a></li>",href);
            string ret = sb.ToString();
            return ret;
        }
    }
    class FeatureInfo
    {
        public string Url { get; set; }
        public string Name { get; set; }
    }
}
